package com.itheima.tlias.controller;

import com.itheima.tlias.dto.AddSubjectDto;
import com.itheima.tlias.dto.CheckSubjectDto;
import com.itheima.tlias.dto.UpdateSubjectDto;
import com.itheima.tlias.service.SubjectService;
import com.itheima.tlias.vo.PageBean;
import com.itheima.tlias.vo.Result;
import com.itheima.tlias.vo.SubjectVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.security.auth.Subject;
import java.util.List;

@RestController
@RequestMapping("/subjects")
public class SubjectController {
    @Autowired
    private SubjectService subjectService;

    @GetMapping
    public Result<PageBean<SubjectVo>> subjectPage(CheckSubjectDto dto) {
        PageBean<SubjectVo> subjects = subjectService.subjectPage(dto);
        return Result.success(subjects);
    }

    @PostMapping
    public Result<Void> addSubject(@RequestBody AddSubjectDto dto) {
        subjectService.add(dto);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result<SubjectVo> selectById(@PathVariable Integer id){
        SubjectVo subjectVo = subjectService.selectById(id);
        return Result.success(subjectVo);
    }
    @PutMapping
    public Result<Void> updateSubject(@RequestBody UpdateSubjectDto dto) {
        subjectService.updateSubject(dto);
        return Result.success();
    }
    @DeleteMapping("/{ids}")
    public Result<Void> deleteByIds(@PathVariable List<Integer> ids){
        subjectService.deleteByIds(ids);
        return Result.success();
    }
}
